<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Http\Server\ManufacturerServer;
use App\Services\JsonResponseService;
use Illuminate\Http\Request;

class ManufacturerController extends Controller
{
    //厂家管理

    public function __construct() {
        $this->server = new ManufacturerServer();
    }

    /**
     * 添加厂家
     * @param Request $request
     */
    public function addManufacturer(Request $request){
        $id = $request->input('id');
        $manufacturer_name = $request->input('manufacturer_name');
        $manufacturer_address = $request->input('manufacturer_address');
        $manufacturer_phone = $request->input('manufacturer_phone');
        $res = $this->server->addManufacturerServer($id,$manufacturer_name,$manufacturer_address,$manufacturer_phone);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }

    /**
     * 获取厂家列表
     */
    public function getManufacturerList(Request $request){
        // 获取查询条件
        $params = $request->only(['manufacturer_name','manufacturer_address','manufacturer_phone']);
        $per_page = $request->input('per_page');
        $res = $this->server->getManufacturerListServer($params,$per_page);
        return JsonResponseService::success($res['data'],$res['msg'],$res['status']);
    }
}
